<?php

namespace backend\models;

use Yii;
use common\models\UserInfo;

/**
 * This is the model class for table "user_message".
 *
 * @property integer $uid
 * @property integer $msgid
 * @property integer $read
 */
class UserMessage extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_message';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['uid', 'msgid'], 'required'],
            [['uid', 'msgid', 'read'], 'integer']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'uid' => 'Uid',
            'msgid' => 'Msgid',
            'read' => 'Read',
        ];
    }
    public function getUsernameByRead()
    {
    	return $this->hasOne(UserInfo::className(), ['id'=>'uid']);
    }

    public function getMsg0()
    {
        return $this->hasOne(SysMessage::className(), ['id' => 'msgid'])->andWhere(['sys_message.status' => 3]);
    }
}
